// pages/xinxiLuru/xinxilu.js
var app = getApp();
var util = require("../../utils/util.js");
var siteinfo = require('../../siteinfo.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        startDate: '',
        endDate: '',
        shebaoList: [],
        shenfzList: [],
        cunzhaoList: [],
        status: 1,
        occupation: '', // 传给后端的申报职业
        timedate: '',// 开班时间
        indexTime: 0,//开班时间默认下标
        timeOptions: {},// 每个职业对应的开班时间选项
        name: '',
        sexList: [{
            id: 0,
            name: '请选择性别'
        }, {
            id: 1,
            name: '男'
        }, {
            id: 2,
            name: '女'
        }],
        indexSex: 0,
        bornDate: '',
        itemsData: [], // 申报科目列表
        educationList: ["请选择学历", '初中', '高中', '中专', '大专', '大学', '硕士', '博士'], //学历
        radioList: [ //人员类别
            { value: 0, name: '学生' },
            { value: 1, name: '企业员工', },
            { value: 2, name: '社会人员' },
        ], // 单选框选择
        gradeList: ["请选择类型", '三级', '四级', '五级'], // 申报认定等级
        professionList: [],// 申报职业列表
        indexNation: 0, //申报职业index
        indexEducation: 0, // 学历下标
        education: '', //学历
        major: '', // 所学专业
        peType: 10000,// 人员类别
        sfzaddress: '', // 身份证地址
        sfznumber: '',// 身份证号
        workUnit: '', // 工作单位
        zhiye: '', // 申报职业
        kaibanTime: '', // 开班时间
        declarationLevel: '',// 申报认定等级
        indexDeclarationLevel: 0, // 申报认定等级下标
        subject: '',// 申报科目
        bookList: [], // 证书信息
        workjlList: [], // 工作经历
        idFront: '/image/addPic.png', //寸照
        imagesFront: '/image/addPic.png',
        idReverse: '/image/addPic.png', //身份证复印件
        imagesReverse: '/image/addPic.png',
        imagesXueli: '/image/addPic.png', // 社保证明
        recordCertificate: '/image/addPic.png',
        editdataList: {}, // 编辑回显数据
        reason: '',
        editId: '',
        showTime: '',
        birthTime:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        // 计算并设置日期范围
        this.calculateDateRange();
        this.handleGetBkTime()
        if (options.datalist) {
            if (JSON.parse(options.datalist).declaredLevel == '三级') {
                this.setData({
                    indexDeclarationLevel: 1
                })
            }
            if (JSON.parse(options.datalist).declaredLevel == '四级') {
                this.setData({
                    indexDeclarationLevel: 2
                })
            }
            if (JSON.parse(options.datalist).declaredLevel == '五级') {
                this.setData({
                    indexDeclarationLevel: 3
                })
            }
            console.log(JSON.parse(options.datalist), 'esadfa');
            this.setData({
                editId: JSON.parse(options.datalist).id,
                reason: JSON.parse(options.datalist).reason,
                status: 2,
                name: JSON.parse(options.datalist).name,
                indexSex: JSON.parse(options.datalist).sex,
                bornDate: JSON.parse(options.datalist).born,
                indexEducation: JSON.parse(options.datalist).education,
                major: JSON.parse(options.datalist).major,
                peType: JSON.parse(options.datalist).personType,
                certificateType: '0',
                sfzaddress: JSON.parse(options.datalist).idcardAddress,
                sfznumber: JSON.parse(options.datalist).idcardNumber,
                workUnit: JSON.parse(options.datalist).workUnit,
                timedate: JSON.parse(options.datalist).examTime,
                showTime: JSON.parse(options.datalist).examTime,
                careerYears: JSON.parse(options.datalist).workTime,
                occupation: JSON.parse(options.datalist).declaredCareers,
                // declaredSubject: this.data.sbKemu,
                itemsData: JSON.parse(options.datalist).declaredSubject.split(','),
                idFront: JSON.parse(options.datalist).personPhoto,
                idReverse: JSON.parse(options.datalist).idcardPhoto,
                recordCertificate: JSON.parse(options.datalist).graducationPhoto,
                imagesFront: JSON.parse(options.datalist).personPhoto,
                imagesReverse: JSON.parse(options.datalist).idcardPhoto,
                imagesXueli: JSON.parse(options.datalist).graducationPhoto, // 社保证明
                shebaoList: JSON.parse(JSON.parse(options.datalist).graducationPhoto),
                shenfzList: JSON.parse(JSON.parse(options.datalist).idcardPhoto),
                // cunzhaoList: JSON.parse(JSON.parse(options.datalist).personPhoto),
            })
        }
    },




    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },
    // 参考页面

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.handleGetBookList()
        this.handleGetWorkList()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    calculateDateRange: function () {
        const now = new Date();
        console.log(now.getFullYear()-18,'now');
        const year = now.getFullYear()-18;
        const month = now.getMonth() + 1;
        const day = now.getDate();

        // 计算最大可选日期（18年前）
        const maxDate = `${year}-${this.formatDate(month)}-${this.formatDate(day)}`;
        this.setData({
            endDate: maxDate,
            birthTime:maxDate,
        });
    },
    formatDate: function (value) {
        return value < 10 ? '0' + value : value;
    },


    onChange(event) {
        this.setData({
            itemsData: event.detail,
        });
    },
    handleReference: function () {
        wx.navigateTo({
            url: '/pages/reTemplate/reTemplate'
        })
    },
    // 预览图片
    previewImg: function (e) {
        var index = e.currentTarget.dataset.index;
        var cunzhaoList = this.data.cunzhaoList;
        wx.previewImage({
            current: cunzhaoList[index],
            urls: cunzhaoList
        })
    },
    // 预览图片
    sbpreviewImg: function (e) {
        var index = e.currentTarget.dataset.index;
        var shebaoList = this.data.shebaoList;
        wx.previewImage({
            current: shebaoList[index],
            urls: shebaoList
        })
    },
    // 预览图片
    sfzpreviewImg: function (e) {
        var index = e.currentTarget.dataset.index;
        var shenfzList = this.data.shenfzList;
        wx.previewImage({
            current: shenfzList[index],
            urls: shenfzList
        })
    },
    sbchooseImg: function (e) {
        var that = this;
        wx.chooseImage({
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'],
            success: function (res) {
                var shebaoList = that.data.shebaoList
                var tempFiles = res.tempFiles
                for (var i = 0; i < res.tempFilePaths.length; i++) {
                    if (shebaoList.length >= 9) {
                        that.setData({
                            shebaoList: shebaoList
                        });
                        return false;
                    } else {
                        wx.getImageInfo({
                            src: res.tempFilePaths[i],
                            success(result) {
                                app._uploadFile(siteinfo.fileImprot,
                                    result.path,
                                    'file', {
                                    name: result.name
                                },
                                    function (res1) {
                                        shebaoList.push(res1.data);
                                        that.setData({
                                            shebaoList: shebaoList
                                        })
                                    })
                            }
                        })
                    }
                }
            }

        });
    },
    sfzchooseImg: function (e) {
        var that = this;
        wx.chooseImage({
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'],
            success: function (res) {
                var shenfzList = that.data.shenfzList
                var tempFiles = res.tempFiles
                for (var i = 0; i < res.tempFilePaths.length; i++) {
                    if (shenfzList.length >= 9) {
                        that.setData({
                            shenfzList: shenfzList
                        });
                        return false;
                    } else {
                        wx.getImageInfo({
                            src: res.tempFilePaths[i],
                            success(result) {
                                app._uploadFile(siteinfo.fileImprot,
                                    result.path,
                                    'file', {
                                    name: result.name
                                },
                                    function (res1) {
                                        shenfzList.push(res1.data);
                                        that.setData({
                                            shenfzList: shenfzList
                                        })
                                    })
                            }
                        })
                    }
                }
            }

        });
    },
    sbchooseImg: function (e) {
        var that = this;
        wx.chooseImage({
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'],
            success: function (res) {
                var shebaoList = that.data.shebaoList
                var tempFiles = res.tempFiles
                for (var i = 0; i < res.tempFilePaths.length; i++) {
                    if (shebaoList.length >= 9) {
                        that.setData({
                            shebaoList: shebaoList
                        });
                        return false;
                    } else {
                        wx.getImageInfo({
                            src: res.tempFilePaths[i],
                            success(result) {
                                app._uploadFile(siteinfo.fileImprot,
                                    result.path,
                                    'file', {
                                    name: result.name
                                },
                                    function (res1) {
                                        shebaoList.push(res1.data);
                                        that.setData({
                                            shebaoList: shebaoList
                                        })
                                    })
                            }
                        })
                    }
                }
            }

        });
    },
    chooseImg: function (e) {
        var that = this;
        wx.chooseImage({
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'],
            success: function (res) {
                var cunzhaoList = that.data.cunzhaoList
                var tempFiles = res.tempFiles
                for (var i = 0; i < res.tempFilePaths.length; i++) {
                    if (cunzhaoList.length >= 9) {
                        that.setData({
                            cunzhaoList: cunzhaoList
                        });
                        return false;
                    } else {
                        wx.getImageInfo({
                            src: res.tempFilePaths[i],
                            success(result) {
                                app._uploadFile(siteinfo.fileImprot,
                                    result.path,
                                    'file', {
                                    name: result.name
                                },
                                    function (res1) {
                                        cunzhaoList.push(res1.data);
                                        that.setData({
                                            cunzhaoList: cunzhaoList
                                        })
                                    })
                            }
                        })
                    }
                }
            }

        });
    },
    // 删除图片
    deleteImg: function (e) {
        var cunzhaoList = this.data.cunzhaoList;
        var index = e.currentTarget.dataset.index;
        cunzhaoList.splice(index, 1);
        this.setData({
            cunzhaoList: cunzhaoList
        });
        console.log(this.data.cunzhaoList);
    },
    // 删除图片
    sbdeleteImg: function (e) {
        var shebaoList = this.data.shebaoList;
        var index = e.currentTarget.dataset.index;
        shebaoList.splice(index, 1);
        this.setData({
            shebaoList: shebaoList
        });
    },

    // 删除图片
    sfzdeleteImg: function (e) {
        var shenfzList = this.data.shenfzList;
        var index = e.currentTarget.dataset.index;
        shenfzList.splice(index, 1);
        this.setData({
            shenfzList: shenfzList
        });
    },
    // 查询证书信息
    handleGetBookList: function () {
        let token = wx.getStorageSync('token');
        wx.request({
            url: siteinfo.siteroot3 + 'jzApi/certificateInfo/getUserCertificate',
            header: {
                'Authorization': token,
                'content-type': 'application/json'
            },
            method: 'GET',
            success: (res) => {
                console.log(res, 'book');
                this.setData({
                    bookList: res.data.data
                })
            }
        });
    },
    // 查询工作信息
    handleGetWorkList: function () {
        let token = wx.getStorageSync('token');
        wx.request({
            url: siteinfo.siteroot3 + 'jzApi/workExperince/getUserExperince',
            header: {
                'Authorization': token,
                'content-type': 'application/json'
            },
            method: 'GET',
            success: (res) => {
                this.setData({
                    workjlList: res.data.data
                })
            }
        });
    },
    // 提交
    handleBtnSubMit: function () {
        let token = wx.getStorageSync('token')
        if (!token) {
            app.showError('请先登录后提交!')
            return false
        } else {
            var that = this
            if (this.data.name == '') {
                app.showError('请输入姓名!')
                return false;
            }
            // if (this.data.mobile == '') {
            //     app.showError('请输入手机号!')
            //     return false;
            // }
            // if (this.data.mobile == '') {
            //     app.showError('请输入手机号!')
            //     return false;
            // }
            if (this.data.indexSex == '') {
                app.showError('请选择性别!')
                return false;
            }
            if (this.data.bornDate == '') {
                app.showError('请选择出生日期!')
                return false;
            }
            if (this.data.indexEducation == 0) {
                app.showError('请选择学历!')
                return false;
            }
            if (this.data.major == '') {
                app.showError('请输入所学专业!')
                return false;
            }
            if (this.data.peType == 10000) {
                app.showError('请选择人员类别!')
                return false;
            }
            if (this.data.sfzaddress == '') {
                app.showError('请输入身份证地址!')
                return false;
            }
            if (this.data.sfznumber == '') {
                app.showError('请输入身份证号!')
                return false;
            }

            if (this.data.timedate == '请选择报考时间' || this.data.timedate == '') {
                app.showError('请选择报考时间!')
                return false;
            }
            if (this.data.indexDeclarationLevel == 0) {
                app.showError('请选择申报认定等级!')
                return false;
            }
            // if (this.data.sbKemu == 10000) {
            //     app.showError('请选择申报科目!')
            //     return false;
            // }
            if (this.data.itemsData.length < 1) {
                app.showError('请选择申报科目!')
                return false;
            }
            // if (this.data.cunzhaoList.length<1) {
            //     app.showError('请上传2寸白底寸照!')
            //     return false;
            // }
            if (this.data.shenfzList.length < 1) {
                app.showError('请上传身份证正反面复印件!')
                return false;
            }
            if (this.data.shebaoList.length < 1) {
                app.showError('请上传毕业证!')
                return false;
            }
            if (this.data.indexDeclarationLevel == 1) {
                this.setData({
                    indexDeclarationLevel: '三级'
                })
            }
            if (this.data.indexDeclarationLevel == 2) {
                this.setData({
                    indexDeclarationLevel: '四级'
                })
            }
            if (this.data.indexDeclarationLevel == 3) {
                this.setData({
                    indexDeclarationLevel: '五级'
                })
            }
            let transformedDeclaredSubject = this.data.itemsData.map(subject => {
                switch (subject) {
                    case '理论':
                        return '0';
                    case '实操':
                        return '1';
                    case '综合':
                        return '2';
                    default:
                        // 如果有不在预期范围内的值，根据情况决定处理方式，这里选择忽略或报错
                        // return ''; // 或者 throw new Error('Unexpected subject value: ' + subject);
                        return subject; // 保持原样，确保不破坏数据完整性
                }
            }).join(',');
            let token = wx.getStorageSync('token');
            wx.request({
                url: siteinfo.siteroot3 + 'jzApi/informationImportUser/saveUserInfo',
                method: 'POST',
                header: {
                    'Authorization': token,
                    'content-type': 'application/json'
                },
                data: {
                    name: this.data.name,
                    mobile: this.data.mobile,
                    sex: this.data.indexSex,
                    born: this.data.bornDate,
                    education: this.data.indexEducation,
                    major: this.data.major,
                    personType: this.data.peType,
                    certificateType: '0',
                    idcardAddress: this.data.sfzaddress,
                    idcardNumber: this.data.sfznumber,
                    workUnit: this.data.workUnit,
                    examTime: this.data.timedate,
                    workTime: this.data.careerYears,
                    declaredCareers: this.data.occupation,
                    declaredLevel: this.data.indexDeclarationLevel,
                    // declaredSubject: this.data.sbKemu,
                    declaredSubject: transformedDeclaredSubject,
                    personPhoto: this.data.idFront,
                    // idcardPhoto: this.data.idReverse,
                    // graducationPhoto: this.data.recordCertificate,
                    // personPhoto: JSON.stringify(this.data.cunzhaoList),
                    idcardPhoto: JSON.stringify(this.data.shenfzList),
                    graducationPhoto: JSON.stringify(this.data.shebaoList),
                    certificateInfoConds: this.data.bookList,
                    experinceConds: this.data.workjlList,
                },
                success: function (res) {
                    if (res.data.code == '0') {
                        wx.redirectTo({
                            url: '/pages/entryCompleted/entryCompleted'
                        })
                    } else {
                        console.log(that.data.indexDeclarationLevel);
                        if (that.data.indexDeclarationLevel == '三级') {
                            that.setData({
                                indexDeclarationLevel: 1
                            })
                        }
                        if (that.data.indexDeclarationLevel == '四级') {
                            that.setData({
                                indexDeclarationLevel: 2
                            })
                        }
                        if (that.data.indexDeclarationLevel == '五级') {
                            that.setData({
                                indexDeclarationLevel: 3
                            })
                        }
                        app.showError(res.data.msg)
                        return false;
                    }
                }
            });
        }

    },
    // 重新提交
    handleReBtnSubMit: function () {
        var that = this
        if (this.data.name == '') {
            app.showError('请输入姓名!')
            return false;
        }
        // if (this.data.mobile == '') {
        //     app.showError('请输入手机号!')
        //     return false;
        // }
        // if (this.data.mobile == '') {
        //     app.showError('请输入手机号!')
        //     return false;
        // }
        if (this.data.indexSex == '') {
            app.showError('请选择性别!')
            return false;
        }
        if (this.data.bornDate == '') {
            app.showError('请选择出生日期!')
            return false;
        }
        if (this.data.indexEducation == 0) {
            app.showError('请选择学历!')
            return false;
        }
        if (this.data.major == '') {
            app.showError('请输入所学专业!')
            return false;
        }
        if (this.data.peType == 10000) {
            app.showError('请选择人员类别!')
            return false;
        }
        if (this.data.sfzaddress == '') {
            app.showError('请输入身份证地址!')
            return false;
        }
        if (this.data.sfznumber == '') {
            app.showError('请输入身份证号!')
            return false;
        }

        if (this.data.timedate == '请选择报考时间' || this.data.timedate == '') {
            app.showError('请选择报考时间!')
            return false;
        }
        if (this.data.indexDeclarationLevel == 0) {
            app.showError('请选择申报认定等级!')
            return false;
        }
        // if (this.data.sbKemu == 10000) {
        //     app.showError('请选择申报科目!')
        //     return false;
        // }
        if (this.data.itemsData.length < 1) {
            app.showError('请选择申报科目!')
            return false;
        }
        if (this.data.imagesFront == '/image/addPic.png') {
            app.showError('请上传2寸白底寸照!')
            return false;
        }
        if (this.data.imagesReverse == '/image/addPic.png') {
            app.showError('请上传身份证正反面复印件!')
            return false;
        }
        if (this.data.imagesXueli == '/image/addPic.png') {
            app.showError('请上传毕业证!')
            return false;
        }
        if (this.data.indexDeclarationLevel == 1) {
            this.setData({
                indexDeclarationLevel: '三级'
            })
        }
        if (this.data.indexDeclarationLevel == 2) {
            this.setData({
                indexDeclarationLevel: '四级'
            })
        }
        if (this.data.indexDeclarationLevel == 3) {
            this.setData({
                indexDeclarationLevel: '五级'
            })
        }
        let transformedDeclaredSubject = this.data.itemsData.map(subject => {
            switch (subject) {
                case '理论':
                    return '0';
                case '实操':
                    return '1';
                case '综合':
                    return '2';
                default:
                    // 如果有不在预期范围内的值，根据情况决定处理方式，这里选择忽略或报错
                    // return ''; // 或者 throw new Error('Unexpected subject value: ' + subject);
                    return subject; // 保持原样，确保不破坏数据完整性
            }
        }).join(',');
        let token = wx.getStorageSync('token');
        wx.request({
            url: siteinfo.siteroot3 + 'jzApi/informationImportUser/updateUserInfo',
            method: 'POST',
            header: {
                'Authorization': token,
                'content-type': 'application/json'
            },
            data: {
                id: this.data.editId,
                name: this.data.name,
                mobile: this.data.mobile,
                sex: this.data.indexSex,
                born: this.data.bornDate,
                education: this.data.indexEducation,
                major: this.data.major,
                personType: this.data.peType,
                certificateType: '0',
                idcardAddress: this.data.sfzaddress,
                idcardNumber: this.data.sfznumber,
                workUnit: this.data.workUnit,
                examTime: this.data.showTime,
                workTime: this.data.careerYears,
                declaredCareers: this.data.occupation,
                declaredLevel: this.data.indexDeclarationLevel,
                // declaredSubject: this.data.sbKemu,
                declaredSubject: transformedDeclaredSubject,
                personPhoto: this.data.idFront,
                idcardPhoto: JSON.stringify(this.data.shenfzList),
                graducationPhoto: JSON.stringify(this.data.shebaoList),
                certificateInfoConds: this.data.bookList,
                experinceConds: this.data.workjlList,
            },
            success: function (res) {
                if (res.data.code == '0') {
                    wx.redirectTo({
                        url: '/pages/entryCompleted/entryCompleted'
                    })
                } else {
                    if (that.data.indexDeclarationLevel == '三级') {
                        that.setData({
                            indexDeclarationLevel: 1
                        })
                    }
                    if (that.data.indexDeclarationLevel == '四级') {
                        that.setData({
                            indexDeclarationLevel: 2
                        })
                    }
                    if (that.data.indexDeclarationLevel == '五级') {
                        that.setData({
                            indexDeclarationLevel: 3
                        })
                    }
                    app.showError(res.data.msg)
                    return false;
                }
            }
        });
    },
    // 跳转到添加证书
    handleAddBook: function () {
        let token = wx.getStorageSync('token');
        if (!token) {
            app.showError('请先登录!')
            return false
        }
        if (!wx.getStorageSync('sbzhiye')) {
            app.showError('请先选择申报职业再进行添加！');
            return false;
        }
        wx.navigateTo({
            url: '/pages/addCertificate/addCertificate'
        })
    },
    // 跳转到添加工作经历页面
    handleAddExperience: function () {
        let token = wx.getStorageSync('token');
        if (!token) {
            app.showError('请先登录!')
            return false
        }
        if (!wx.getStorageSync('sbzhiye')) {
            app.showError('请先选择申报职业再进行添加！');
            return false;
        }
        wx.navigateTo({
            url: '/pages/addExperience/addExperience'
        })
    },
    // 编辑工作经历
    handleGoEditWork: function (params) {
        let token = wx.getStorageSync('token');
        if (!token) {
            app.showError('请先登录!')
            return false
        }
        wx.navigateTo({
            url: `/pages/addExperience/addExperience?datalist=${JSON.stringify(params.currentTarget.dataset.index)}`,
        })
    },
    // 编辑证书
    handleGoEditBook: function (params) {
        let token = wx.getStorageSync('token');
        if (!token) {
            app.showError('请先登录!')
            return false
        }
        wx.navigateTo({
            url: `/pages/addCertificate/addCertificate?datalist=${JSON.stringify(params.currentTarget.dataset.index)}`,
        })
    },

    // 获取报名信息和时间
    handleGetBkTime: function () {
        let token = wx.getStorageSync('token');
        wx.request({
            url: siteinfo.siteroot3 + 'jzApi/informationBatch/selInformationBatchs',
            header: {
                'Authorization': token,
                'content-type': 'application/json'
            },
            method: 'GET',
            success: (res) => {
                console.log(res);
                if (res.data.code == 0) {
                    this.data.timeOptions = {};
                    // _this.setData(res.data.data);
                    res.data.data.list.forEach(item => {
                        // 使用certificateName作为key，open_time作为value（根据需求，你也可以处理startTime和endTime来生成不同的时间格式或范围）
                        if (item.open_time.includes('，')) {
                            this.data.timeOptions[item.certificateName] = item.open_time.split('，');
                        } else {
                            // 如果open_time不是逗号分隔的，至少保证它是一个单元素数组
                            this.data.timeOptions[item.certificateName] = [item.open_time];
                        }
                    })
                    this.setData({
                        professionList: res.data.data.list.map(item => item.certificateName),
                    });
                    let bkindex = this.data.professionList[this.data.indexTime]
                    console.log(bkindex, 'bk');
                    wx.setStorageSync('sbzhiye', bkindex)
                    if (this.data.status != 2) {
                        this.setData({
                            occupation: bkindex,
                            timedate: this.data.timeOptions[bkindex][this.data.indexTime],
                            bkList: this.data.timeOptions[bkindex],
                        })
                    } else {
                        this.setData({
                            bkList: this.data.timeOptions[bkindex],
                        })
                    }
                } else {
                    app.showError(res.data.msg);
                    _this.setData({
                        isSignUp: false
                    });
                    return false;
                }
            }
        });
    },

    //获取姓名
    getName: function (e) {
        var value = e.detail.value;
        this.setData({
            name: value
        });
    },
    // 获取身份证地址
    getSfzaddress: function (e) {
        var value = e.detail.value;
        this.setData({
            sfzaddress: value
        });
    },
    // 获取身份证地址
    getSfznumber: function (e) {
        var value = e.detail.value;
        this.setData({
            sfznumber: value
        });
    },
    // //获取手机号
    // getIPhone: function (e) {
    //     var value = e.detail.value;
    //     this.setData({
    //         mobile: value
    //     });
    // },
    // 获取工作单位
    getWorkUnit: function (e) {
        var value = e.detail.value;
        this.setData({
            workUnit: value
        });
    },
    //选择性别
    sexChange: function (e) {
        this.setData({
            indexSex: e.detail.value
        })
    },
    //选择开班时间
    timeChange: function (e) {
        console.log(e.detail.value);
        this.setData({
            showTime: this.data.bkList[e.detail.value],
            timedate: this.data.bkList[e.detail.value],
            indexTime: e.detail.value
        })
        console.log(this.data.timedate);
    },
    //选择出生年月
    bindDateChange: function (e) {
        console.log(e.detail.value, '出生日期');
        this.setData({
            bornDate: e.detail.value
        })
    },
    //参加工作时间
    bindDateChanges: function (e) {
        this.setData({
            workDate: e.detail.value
        })
    },

    //申报认定等级
    declarationLevelChange: function (e) {
        var _this = this
        _this.setData({
            indexDeclarationLevel: e.detail.value,
            declarationLevel: _this.data.gradeList[e.detail.value]
        })
    },
    //申报职业
    workChange: function (e) {
        console.log(this.data.indexDeclarationLevel);
        console.log(this.data.gradeList);
        var _this = this
        const index = e.detail.value;
        const profession = this.data.professionList[index];
        console.log(profession, '22233');
        wx.setStorageSync('sbzhiye', profession)
        _this.setData({
            bkList: _this.data.timeOptions[profession] || [],
            indexNation: e.detail.value,
            occupation: _this.data.professionList[e.detail.value]
        })
    },
    // 人员类别选择
    radioChange(e) {
        this.setData({
            peType: e.detail.value
        })
    },
    //申报认定职业
    professionChange: function (e) {
        var _this = this
        _this.setData({
            indexProfession: e.detail.value,
            profession: _this.data.professionList[e.detail.value]
        })
    },
    //选择学历
    educationChange: function (e) {
        var _this = this
        _this.setData({
            indexEducation: e.detail.value,
            education: _this.data.educationList[e.detail.value]
        })
    },
    //获取专业
    getMajor: function (e) {
        this.setData({
            major: e.detail.value
        });
    },
    //获取身份证号
    getIdNumber: function (e) {
        this.setData({
            idNumber: e.detail.value
        })
    },
    chooseImageFront(e) { //寸照
        var _this = this
        wx.chooseImage({
            sizeType: ['original', 'compressed'], //可选择原图或压缩后的图片
            sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
            success: res => {
                console.log(res,'ressss');
                if (res.tempFiles[0].size < 5242880) {
                    wx.getImageInfo({
                        src: res.tempFilePaths[0],
                        success(result) {
                            const tempFilePaths = res.tempFilePaths
                            app._uploadFile(siteinfo.fileImprot,
                                res.tempFiles[0].path,
                                'file', {
                                name: res.tempFiles[0].name
                            },
                                function (res1) {
                                    _this.setData({
                                        idFront: res1.data,
                                        imagesFront: tempFilePaths,
                                    })
                                    // 获取存储的对象
                                    let storedObject = wx.getStorageSync('hcdatalist');
                                    // 确保对象已被正确获取
                                    if (storedObject) {
                                        // 修改对象的属性值
                                        storedObject.personPhoto = _this.data.idFront;
                                        // 存储修改后的对象回storage
                                        wx.setStorageSync('hcdatalist', storedObject);
                                    } else {
                                        console.log('对象未找到');
                                    }
                                    return false;
                                })
                        }
                    })
                } else {
                    app.showError('寸照应小于5M！')
                }
            }
        })
    },
    chooseImageReverse(e) { //身份证正反面
        var _this = this
        wx.chooseImage({
            sizeType: ['original', 'compressed'], //可选择原图或压缩后的图片
            sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
            success: res => {
                if (res.tempFiles[0].size < 5242880) {
                    wx.getImageInfo({
                        src: res.tempFilePaths[0],
                        success(result) {
                            const tempFilePaths = res.tempFilePaths
                            app._uploadFile(siteinfo.fileImprot,
                                res.tempFiles[0].path,
                                'file', {
                                name: res.tempFiles[0].name
                            },
                                function (res1) {
                                    _this.setData({
                                        idReverse: res1.data,
                                        imagesReverse: tempFilePaths,
                                    })
                                    // 获取存储的对象
                                    let storedObject = wx.getStorageSync('hcdatalist');
                                    // 确保对象已被正确获取
                                    if (storedObject) {
                                        // 修改对象的属性值
                                        storedObject.idcardPhoto = _this.data.idReverse;
                                        // 存储修改后的对象回storage
                                        wx.setStorageSync('hcdatalist', storedObject);
                                    } else {
                                        console.log('对象未找到');
                                    }
                                    return false;
                                })
                        }
                    })
                } else {
                    app.showError('寸照应小于5M！')
                }
            }
        })
    },
    chooseImageXueli(e) { //社保证明
        var _this = this
        wx.chooseImage({
            sizeType: ['original', 'compressed'], //可选择原图或压缩后的图片
            sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
            success: res => {
                console.log(res);
                if (res.tempFiles[0].size < 5242880) {
                    wx.getImageInfo({
                        src: res.tempFilePaths[0],
                        success(result) {
                            const tempFilePaths = res.tempFilePaths
                            app._uploadFile(siteinfo.fileImprot,
                                res.tempFiles[0].path,
                                'file', {
                                name: res.tempFiles[0].name
                            },
                                function (res1) {
                                    _this.setData({
                                        recordCertificate: res1.data,
                                        imagesXueli: tempFilePaths,
                                    })
                                    // 获取存储的对象
                                    let storedObject = wx.getStorageSync('hcdatalist');
                                    // 确保对象已被正确获取
                                    if (storedObject) {
                                        // 修改对象的属性值
                                        storedObject.graducationPhoto = _this.data.recordCertificate;
                                        // 存储修改后的对象回storage
                                        wx.setStorageSync('hcdatalist', storedObject);
                                    } else {
                                        console.log('对象未找到');
                                    }
                                    return false;
                                })
                        }
                    })
                } else {
                    app.showError('寸照应小于5M！')
                }
            }
        })
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }

})
